<!DOCTYPE html>
<!--[if IE 8]><html class="no-js lt-ie9" lang="en" > <![endif]-->
<!--[if gt IE 8]><!--> <html class="no-js" lang="en" > <!--<![endif]-->
<head>
  <meta charset="utf-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  
  
  
  <link rel="shortcut icon" href="../img/favicon.ico">
  <title>Elasticsearch插件 - Workflow Core 中文文档</title>
  <link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Lato:400,700|Roboto+Slab:400,700|Inconsolata:400,700" />

  <link rel="stylesheet" href="../css/theme.css" />
  <link rel="stylesheet" href="../css/theme_extra.css" />
  <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/9.12.0/styles/github.min.css" />
  
  <script>
    // Current page data
    var mkdocs_page_name = "Elasticsearch\u63d2\u4ef6";
    var mkdocs_page_input_path = "Elasticsearch.md";
    var mkdocs_page_url = null;
  </script>
  
  <script src="../js/jquery-2.1.1.min.js" defer></script>
  <script src="../js/modernizr-2.8.3.min.js" defer></script>
  <script src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/9.12.0/highlight.min.js"></script>
  <script>hljs.initHighlightingOnLoad();</script> 
  
</head>

<body class="wy-body-for-nav" role="document">

  <div class="wy-grid-for-nav">

    
    <nav data-toggle="wy-nav-shift" class="wy-nav-side stickynav">
    <div class="wy-side-scroll">
      <div class="wy-side-nav-search">
        <a href=".." class="icon icon-home"> Workflow Core 中文文档</a>
        <div role="search">
  <form id ="rtd-search-form" class="wy-form" action="../search.html" method="get">
    <input type="text" name="q" placeholder="Search docs" title="Type search term here" />
  </form>
</div>
      </div>

      <div class="wy-menu wy-menu-vertical" data-spy="affix" role="navigation" aria-label="main navigation">
                <ul>
                    <li class="toctree-l1"><a class="reference internal" href="..">简介</a>
                    </li>
                </ul>
                <ul>
                    <li class="toctree-l1"><a class="reference internal" href="../getting-started/">入门指南</a>
                    </li>
                </ul>
                <ul>
                    <li class="toctree-l1"><a class="reference internal" href="../external-events/">外部事件</a>
                    </li>
                </ul>
                <ul>
                    <li class="toctree-l1"><a class="reference internal" href="../activity-workers/">活动工作者</a>
                    </li>
                </ul>
                <ul>
                    <li class="toctree-l1"><a class="reference internal" href="../error-handling/">错误处理</a>
                    </li>
                </ul>
                <ul>
                    <li class="toctree-l1"><a class="reference internal" href="../control-structures/">控制结构</a>
                    </li>
                </ul>
                <ul>
                    <li class="toctree-l1"><a class="reference internal" href="../saga-transactions/">saga事务</a>
                    </li>
                </ul>
                <ul>
                    <li class="toctree-l1"><a class="reference internal" href="../json-yaml-definitions/">JSON/YAML定义</a>
                    </li>
                </ul>
                <ul>
                    <li class="toctree-l1"><a class="reference internal" href="../persistence/">持久化</a>
                    </li>
                </ul>
                <ul>
                    <li class="toctree-l1"><a class="reference internal" href="../middleware/">中间件</a>
                    </li>
                </ul>
                <ul>
                    <li class="toctree-l1"><a class="reference internal" href="../multi-node-clusters/">多节点集群</a>
                    </li>
                </ul>
                <ul>
                    <li class="toctree-l1"><a class="reference internal" href="../ASPNETCore/">ASP.NET Core</a>
                    </li>
                </ul>
                <ul class="current">
                    <li class="toctree-l1 current"><a class="reference internal current" href="./">Elasticsearch插件</a>
    <ul class="current">
    <li class="toctree-l2"><a class="reference internal" href="#_1">安装</a>
    </li>
    <li class="toctree-l2"><a class="reference internal" href="#_2">配置</a>
    </li>
    <li class="toctree-l2"><a class="reference internal" href="#_3">用法</a>
        <ul>
    <li class="toctree-l3"><a class="reference internal" href="#terms">terms</a>
        <ul>
    <li class="toctree-l4"><a class="reference internal" href="#_4">示例</a>
    </li>
        </ul>
    </li>
    <li class="toctree-l3"><a class="reference internal" href="#skip-take">skip &amp; take</a>
    </li>
    <li class="toctree-l3"><a class="reference internal" href="#filters">filters</a>
        <ul>
    <li class="toctree-l4"><a class="reference internal" href="#_5">示例</a>
    </li>
        </ul>
    </li>
        </ul>
    </li>
    </ul>
                    </li>
                </ul>
                <ul>
                    <li class="toctree-l1"><a class="reference internal" href="../test-helpers/">测试助手</a>
                    </li>
                </ul>
                <ul>
                    <li class="toctree-l1"><a class="reference internal" href="../Extensions/">扩展</a>
                    </li>
                </ul>
                <ul>
                    <li class="toctree-l1"><a class="reference internal" href="../Samples/">示例</a>
                    </li>
                </ul>
      </div>
    </div>
    </nav>

    <section data-toggle="wy-nav-shift" class="wy-nav-content-wrap">

      
      <nav class="wy-nav-top" role="navigation" aria-label="top navigation">
        <i data-toggle="wy-nav-top" class="fa fa-bars"></i>
        <a href="..">Workflow Core 中文文档</a>
      </nav>

      
      <div class="wy-nav-content">
        <div class="rst-content">
          <div role="navigation" aria-label="breadcrumbs navigation">
  <ul class="wy-breadcrumbs">
    <li><a href="..">Docs</a> &raquo;</li>
    
      
    
    <li>Elasticsearch插件</li>
    <li class="wy-breadcrumbs-aside">
      
    </li>
  </ul>
  
  <hr/>
</div>
          <div role="main">
            <div class="section">
              
                <h1 id="workflow-coreelasticsear">Workflow Core的Elasticsear插件</h1>
<p>A search index plugin for Workflow Core backed by Elasticsearch, enabling you to index your workflows and search against the data and state of them.</p>
<h2 id="_1">安装</h2>
<p>安装NuGet 包"WorkflowCore.Providers.Elasticsearch"</p>
<p>使用 Nuget package console</p>
<pre><code>PM&gt; Install-Package WorkflowCore.Providers.Elasticsearch
</code></pre>
<p>使用 .NET CLI</p>
<pre><code>dotnet add package WorkflowCore.Providers.Elasticsearch
</code></pre>
<h2 id="_2">配置</h2>
<p>Use the <code>.UseElasticsearch</code> extension method on <code>IServiceCollection</code> when building your service provider</p>
<pre><code>using Nest;
...
services.AddWorkflow(cfg =&gt;
{
    ...
    cfg.UseElasticsearch(new ConnectionSettings(new Uri(&quot;http://localhost:9200&quot;)), &quot;index_name&quot;);
});
</code></pre>
<h2 id="_3">用法</h2>
<p>Inject the <code>ISearchIndex</code> service into your code and use the <code>Search</code> method.</p>
<pre><code>Search(string terms, int skip, int take, params SearchFilter[] filters)
</code></pre>
<h4 id="terms">terms</h4>
<p>A whitespace separated string of search terms, an empty string will match everything. This will do a full text search on the following default fields * Reference * Description * Status * Workflow Definition</p>
<p>In addition you can search data within your own custom data object if it implements <code>ISearchable</code></p>
<pre><code class="language-csharp">using WorkflowCore.Interfaces; 

public class MyData : ISearchable 
{
  public string StrValue1 { get; set; } 

  public string StrValue2 { get; set; }
  public IEnumerable&lt;string&gt; GetSearchTokens()
  {
    return new List&lt;string&gt;()
    {
        StrValue1,
        StrValue2
    };    
  }
}
</code></pre>
<h5 id="_4">示例</h5>
<p>Search all fields for "puppies" <code>searchIndex.Search("puppies", 0, 10);</code></p>
<h4 id="skip-take">skip &amp; take</h4>
<p>Use <code>skip</code> and <code>take</code> to page your search results. Where <code>skip</code> is the result number to start from and <code>take</code> is the page size.</p>
<h4 id="filters">filters</h4>
<p>You can also supply a list of filters to apply to the search, these can be applied to both the standard fields as well as any field within your custom data objects. There is no need to implement <code>ISearchable</code> on your data object in order to use filters against it.</p>
<p>The following filter types are available * ScalarFilter * DateRangeFilter * NumericRangeFilter * StatusFilter</p>
<p>These exist in the <code>WorkflowCore.Models.Search</code> namespace.</p>
<h5 id="_5">示例</h5>
<p>Filtering by reference ``` using WorkflowCore.Models.Search; ...</p>
<p>searchIndex.Search("", 0, 10, ScalarFilter.Equals(x =&gt; x.Reference, "My Reference")); ```</p>
<p>Filtering by workflows started after a date <code>searchIndex.Search("", 0, 10, DateRangeFilter.After(x =&gt; x.CreateTime, startDate));</code></p>
<p>Filtering by workflows completed within a period <code>searchIndex.Search("", 0, 10, DateRangeFilter.Between(x =&gt; x.CompleteTime, startDate, endDate));</code></p>
<p>Filtering by workflows in a state <code>searchIndex.Search("", 0, 10, StatusFilter.Equals(WorkflowStatus.Complete));</code></p>
<p>Filtering against your own custom data class ```</p>
<p>class MyData { public string Value1 { get; set; } public int Value2 { get; set; } }</p>
<p>searchIndex.Search("", 0, 10, ScalarFilter.Equals(x =&gt; x.Value1, "blue moon")); searchIndex.Search("", 0, 10, NumericRangeFilter.LessThan(x =&gt; x.Value2, 5)) ```</p>
              
            </div>
          </div>
          <footer>
  
    <div class="rst-footer-buttons" role="navigation" aria-label="footer navigation">
      
        <a href="../test-helpers/" class="btn btn-neutral float-right" title="测试助手">Next <span class="icon icon-circle-arrow-right"></span></a>
      
      
        <a href="../ASPNETCore/" class="btn btn-neutral" title="ASP.NET Core"><span class="icon icon-circle-arrow-left"></span> Previous</a>
      
    </div>
  

  <hr/>

  <div role="contentinfo">
    <!-- Copyright etc -->
    
  </div>

  Built with <a href="https://www.mkdocs.org/">MkDocs</a> using a <a href="https://github.com/snide/sphinx_rtd_theme">theme</a> provided by <a href="https://readthedocs.org">Read the Docs</a>.
</footer>
      
        </div>
      </div>

    </section>

  </div>

  <div class="rst-versions" role="note" aria-label="versions">
    <span class="rst-current-version" data-toggle="rst-current-version">
      
      
        <span><a href="../ASPNETCore/" style="color: #fcfcfc;">&laquo; Previous</a></span>
      
      
        <span style="margin-left: 15px"><a href="../test-helpers/" style="color: #fcfcfc">Next &raquo;</a></span>
      
    </span>
</div>
    <script>var base_url = '..';</script>
    <script src="../js/theme.js" defer></script>
      <script src="../search/main.js" defer></script>
    <script defer>
        window.onload = function () {
            SphinxRtdTheme.Navigation.enable(true);
        };
    </script>

</body>
</html>
